
package com.qf.service.impl;

import java.util.List;

import com.qf.dao.impl.ProductDaoImpl;
import com.qf.model.Product;
import com.qf.model.Pagebean;
import com.qf.service.ProductService;

public class ProductServiceImpl implements ProductService{
	private ProductDaoImpl productDaoImpl=new ProductDaoImpl();

	@Override
	public Pagebean findother(int currentPage, int pagesize, int cid) {
		
		Pagebean p1 = new Pagebean();
		String sql="select * from product where cid=?";
		List<Product> list = productDaoImpl.findother(sql, cid);
		p1.setCurrentPage(currentPage);//当前页
		p1.setPagesize(pagesize);//每页的数据
		int size = list.size();
		p1.setTotalCount(size);//数据总个数
		int tatalPagesize=size%pagesize==0?size/pagesize:size/pagesize+1;
		p1.setTatalPagesize(tatalPagesize);//总页数
		
		String sql_="select * from product where cid=? limit ?,?";
		
		List<Product> list_ = productDaoImpl.findother(sql_, cid,(currentPage-1)*pagesize,pagesize);
		
		p1.setList(list_);//总数据
		return p1;
			
	}

	@Override
	public Product findByPid(String pid) {
		
		//TODO
		return productDaoImpl.findByPid(pid);
			
	}

	public Pagebean findother(int currentPage, int pagesize, String name) {
		
		Pagebean p = new Pagebean();
		p.setCurrentPage(currentPage);
		p.setPagesize(pagesize);
		String sql="select * from product where pid like ? or pname like ? or pdesc like ?";
		List<Product> list = productDaoImpl.findother(sql, "%"+name+"%","%"+name+"%","%"+name+"%");
		
		int size = list.size();
		p.setTotalCount(size);
		int tatalPagesize=size%pagesize==0?size%pagesize:size/pagesize+1;
		p.setTatalPagesize(tatalPagesize);
		String sql_="select * from product where pid like ? or pname like ? or pdesc like ? limit ?,?";
		List<Product> list_ = productDaoImpl.findother(sql_, "%"+name+"%","%"+name+"%","%"+name+"%",(currentPage-1)*pagesize,pagesize);
		p.setList(list_);
		return p;
			
	}

	
	

}

	